/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pehulja.mmdo.coursework.math;

import java.io.Serializable;

/**
 *
 * @author pehulja
 */
public class Term implements Cloneable, Serializable{
    private Byte id;
    private Double factor;
    private Double degree;

    public Term(double factor, double degree, byte id) {
        this.factor = factor;
        this.id = id;
        this.degree = degree;
    }

    public Term() {

    }

    public Byte getId() {
        return id;
    }

    public void setId(Byte id) {
        this.id = id;
    }

    public Double getFactor() {
        return factor;
    }

    public void setFactor(Double factor) {
        this.factor = factor;
    }

    public Double getDegree() {
        return degree;
    }

    public void setDegree(Double degree) {
        this.degree = degree;
    }

    public Double count (Double input){
        System.out.println(Math.pow(input.doubleValue(), degree.doubleValue()));
        return factor.doubleValue()*Math.pow(input.doubleValue(), degree.doubleValue());
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        if(factor>0){
            builder.append("+");
        builder.append(factor.toString());
            if((degree==0 && factor==0) || (id>=0))
                builder.append("x("+Integer.toString(id+1)+")");
            if((degree==0 && factor==0) || (degree > 1))
                builder.append("^("+degree.toString().toString()+")");
        }
        return builder.toString();
    }

    public Term copy() {
        return new Term(this.getFactor().doubleValue(), this.getDegree().doubleValue(), this.getId().byteValue());
    }
}
